package gw.com.android.ui.views;

import android.content.Context;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gwtsz.gts2.hx.R;

import gw.com.android.app.AppMain;
import www.com.library.app.Logger;

/**
 * Created by jay on 2017/6/29.
 */

public class AccountLockingView extends LinearLayout {

    private Context cxt;
    private TextView lockTip1;
    private TextView lockTip2;
    private SpannableString mSpannableStringTip1;
    private SpannableString mSpannableStringTip2;
    private TipsBtnClickListener mCallback;// 按钮点击事件监听器
    public AccountLockingView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    public AccountLockingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public AccountLockingView(Context context) {
        super(context);
        init(context);
    }

    private void init(Context ctx) {
        cxt = ctx;
        View view = LayoutInflater.from(ctx).inflate(R.layout.lccountlockinglayout, this, true);
        lockTip1 = (TextView) view.findViewById(R.id.tv_tip1);
        lockTip2 = (TextView) view.findViewById(R.id.tv_tip2);
        mSpannableStringTip1 = new SpannableString(AppMain.getAppString(R.string.account_locking_tip1));
        mSpannableStringTip2 = new SpannableString(AppMain.getAppString(R.string.account_locking_tip2));
        mSpannableStringTip1.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Logger.i("忘记密码");
                mCallback.onBtnClick(widget.getId());
            }
            @Override
            public void updateDrawState(TextPaint ds) {
                super.updateDrawState(ds);
                ds.setColor(getResources().getColor(R.color.color_contact_a)); //设置颜色
                ds.setUnderlineText(false);
            }
        }, 12, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        mSpannableStringTip2.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Logger.i("联系客服");
                mCallback.onBtnClick(widget.getId());
            }
            @Override
            public void updateDrawState(TextPaint ds) {
                super.updateDrawState(ds);
                ds.setColor(getResources().getColor(R.color.color_contact_a)); //设置颜色
                ds.setUnderlineText(false);
            }
        }, 5, 9, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        lockTip1.setMovementMethod(LinkMovementMethod.getInstance());
        lockTip2.setMovementMethod(LinkMovementMethod.getInstance());
        lockTip1.setText(mSpannableStringTip1);
        lockTip2.setText(mSpannableStringTip2);
    }

    /**
     * 设置按钮点击监听事件
     *
     * @param mCallback
     */
    public void setBtnClickListener(TipsBtnClickListener mCallback) {
        this.mCallback = mCallback;
    }
    /**
     * Created by Jay on 2016/7/7.
     * 自定义控件的按钮点击操作回调
     */
    public interface TipsBtnClickListener {
        /**
         * 按钮点击监听器回调函数
         *
         * @param viewID 按钮id
         */
        void onBtnClick(int viewID);
    }

}
